package com.blog.wl2023.repository;

import com.blog.wl2023.entity.ArticleComment;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author wule
 * @desc
 */
@Repository
public interface ArticleCommentRepository extends JpaRepository<ArticleComment, Long> , JpaSpecificationExecutor<ArticleComment> {

	@Modifying
	@Transactional
	@Query("update ArticleComment a set a.isDelete=:isDelete where a.uuid = :uuid")
	void updateCommentIsDelete(String uuid, Integer isDelete);

	@Query(value = "SELECT ac from ArticleComment ac JOIN FETCH ac.user where ac.isDelete = 0 AND ac.articleId = :articleUUid and ac.pId <> '0'")
	List<ArticleComment> findArticleChildComment(String articleUUid);

	@Query(value = "SELECT ac from ArticleComment ac JOIN FETCH ac.user where ac.articleId = :articleUUid and ac.pId <> '0'")
	List<ArticleComment> findAdminArticleChildComment(String articleUUid);
}
